package com.it.base.service.impl;


import com.it.base.entity.BaseEntity;
import com.it.base.mapper.BaseMapper;
import com.it.base.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import java.time.LocalDate;
import java.util.List;

/**
 * @program: learning
 * @description:
 * @author: Lefnmg
 * @create: 2018-11-02 23:18
 **/
public class BaseService<T,R extends BaseMapper<T>> implements IBaseService<T> {

    @Autowired
    public R baseMapper;



    @Override
    public <S extends T> List<T> findList(S s) {
        return baseMapper.findList(s);
    }

    @Override
    public T findById(Long id) {
        return baseMapper.findById(id);
    }

    @Override
    public int insert(T t) {
        if (t instanceof BaseEntity){
            ((BaseEntity)t).setCreateTime(LocalDate.now());
        }
        return baseMapper.insert(t);
    }

    @Override
    public int update(T t) {
        return baseMapper.update(t);
    }

    @Override
    public int delete(Long id) {
        return baseMapper.delete(id);
    }

    @Override
    public T findByCondition(T t) {
        return baseMapper.findByCondition(t);
    }

    @Override
    public T findByName(String name) {
        return baseMapper.findByName(name);
    }
}
